package baidu;

/**
 * @author zc
 * @version 1.0
 * @date 2021/9/7 16:14
 *
 * [对象只会自救一次]
 */
public class TestGC {

    private static TestGC TEST_GC = null;

    private void isAlive() {
        System.out.print("Yes,I'm Alive!" + "、");
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.print("finalize mehtod executed!" + "、");
        TestGC.TEST_GC = this;
    }

    public static void main(String[] args) throws Throwable {
        TEST_GC = new TestGC();
        TEST_GC = null;
        System.gc();
        Thread.sleep(500);
        if (TEST_GC != null) {
            TEST_GC.isAlive();
        } else {
            System.out.print("NO,I'm dead!" + "、");
        }
        TEST_GC = null;
        System.gc();
        Thread.sleep(500);
        if (TEST_GC != null) {
            TEST_GC.isAlive();
        } else {
            System.out.print("NO,I'm dead!");
        }
    }
}
